#ifndef SOCKET_CHANNEL
#define SOCKET_CHANNEL

#include "../channel/channel.h"
#include <cstdint>
#include <memory>
#include <vector>
#include <functional>
#include <openssl/bio.h>

class Loop;
class Description;
class SocketChannel : public ChannelProtocol,
                      public std::enable_shared_from_this<SocketChannel>
{
public:
    using PostFunc = std::function<void()>;
    SocketChannel(Loop * loop, const std::shared_ptr<Description> & description);
    ~SocketChannel() override;
    void    OnEvent(EventData & data) override;
    int     AddEvent(int event) override;
    int     DelEvent() override;
    int     ModEvent(int event) override;
    int     DescriptionData() override;
    int64_t Index() override;
    void    Index(int64_t index) override;
    virtual void OnWriteEvent(std::shared_ptr<SocketChannel> channel, std::shared_ptr<Description> description);
    virtual void OnReadEvent(std::shared_ptr<SocketChannel>  channel, std::shared_ptr<Description> description);
    virtual void OnErrorEvent(std::shared_ptr<SocketChannel> channel, std::shared_ptr<Description> description);
    void    Post(PostFunc && func);
private:
    Loop *                       m_loop;
    std::shared_ptr<Description> m_description;
    int64_t                      m_index{};
    std::vector<PostFunc>        m_post_func;
    int                          m_event_mode{};
};

#endif
